<?php
/**
 * Created by PhpStorm.
 * User: yzg
 * Date: 2015/9/15
 * Time: 15:00
 */

/**
 * Class Weixin_Windex_module
 */
class Weixin_Datan_module extends CI_Module
{
    public $weixin_model;
    public $Orderinfo_model;
    public $setting;
    public $sid;

    public function __construct()
    {
        parent::__construct();
        $this->sid = $GLOBALS['sid'];
        $this->load->model('weixin.weixin_model');
        $this->load->model('expert.Expert_model');
        $this->setting = $this->weixin_model->db_get_setting();
        $this->adminid = $this->session->userdata('admin_user_id');
        if (!$this->adminid) {
            redirect(site_url('admin/index/login'));
        }
        $this->load->model('order.Orderinfo_model');
        $this->load->model('line.Line_view_model');
        $this->load->model('member.User_model');
        $this->load->model('weixin.shop_model');
       
        $this->load->model('line.Site_view_model');
    }


    /**
     * 站点访问量统计
     */
    public function siteview(){
        $this->data['title'] = '访问量统计';
        $this->data['view'] = 'siteview_chart';

        $startdate = $this->input->get_post('start_date');
        $enddate = $this->input->get_post('end_date');
        $type = $this->input->get_post('type');//views浏览量shares分享量adds添加量
        $type_array = array('views'=>'网站访问浏览量','shares'=>'线路分享量','adds'=>'线路添加量');


        if(empty($enddate))$enddate = date('Y-m-d',strtotime("today"));
        if(empty($startdate))$startdate= date('Y-m-d',strtotime("-1 month"));
        if(empty($type))$type = 'views';


        $condition['startdate'] = $startdate;
        $condition['enddate']   = $enddate;
        $condition['type']      = $type;
        $this->data['condition'] = $condition;
        $this->data['type_name'] = $type_array[$type];
        $starttime=strtotime($startdate);
        $endtime=strtotime($enddate);
        $end_day=round(($endtime-$starttime)/86400);
        $add = date('j',$starttime);
        $date_array = array();
        for($day=$add; $day<=$end_day+$add; $day++){
            //echo $day;
            $temp_date = date("Y-m-d",mktime(0,0,0,date('m',$starttime),$day,date('Y',$starttime)));//
            array_push($date_array,$temp_date);
        }
        //print_r($date_array);exit;
        foreach ($date_array as $k => $v) {
            $data_array[$k] = $this->Site_view_model->fetch_count_by_date($v, $date_array[$k+1],$type);
        }

        $this->data['date_array'] = $date_array;
        $this->data['data_array'] = $data_array;
        $this->data['index_url'] = site_url('weixin/datan/siteview');

        if($_GET['ifr']){
            $this->loadview($this->data, 'xenon/siteview_chart');
        }else {
            $this->loadview($this->data, 'xenon/common/index');
        }
    }
    /**
     * 线路统计
     */
    public function tj_line()
    {
        $this->data['title'] = '订单统计';
        $this->data['view'] = 'line_chart';

        $startdate = $this->input->get_post('start_date');
        $enddate = $this->input->get_post('end_date');
        $type = $this->input->get_post('type');//views浏览量shares分享量adds添加量
        $type_array = array('views'=>'线路浏览量','shares'=>'线路分享量','adds'=>'线路添加量');


        if(empty($enddate))$enddate = date('Y-m-d',strtotime("today"));
        if(empty($startdate))$startdate= date('Y-m-d',strtotime("-1 month"));
        if(empty($type))$type = 'views';


        $condition['startdate'] = $startdate;
        $condition['enddate']   = $enddate;
        $condition['type']      = $type;
        $this->data['condition'] = $condition;
        $this->data['type_name'] = $type_array[$type];
        $starttime=strtotime($startdate);
        $endtime=strtotime($enddate);
        $end_day=round(($endtime-$starttime)/86400);
        $add = date('j',$starttime);
        $date_array = array();
        for($day=$add; $day<=$end_day+$add; $day++){
            //echo $day;
            $temp_date = date("Y-m-d",mktime(0,0,0,date('m',$starttime),$day,date('Y',$starttime)));//
            array_push($date_array,$temp_date);
        }
        //print_r($date_array);exit;
        foreach ($date_array as $k => $v) {
            $data_array[$k] = $this->Line_view_model->fetch_count_by_date($v, $date_array[$k+1],$type);
        }
//        print_r($date_array);exit;

        $this->data['date_array'] = $date_array;
        $this->data['data_array'] = $data_array;
        if($_GET['ifr']){
            $this->loadview($this->data, 'xenon/line_chart');
        }else {
            $this->loadview($this->data, 'xenon/common/index');
        }
    }
}
